﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.UI;

namespace Terraria.GameContent.UI.Elements
{
	// Token: 0x020003FF RID: 1023
	public class UIToggleImage : UIElement
	{
		// Token: 0x17000293 RID: 659
		// (get) Token: 0x060023F5 RID: 9205 RVA: 0x00019743 File Offset: 0x00017943
		public bool IsOn
		{
			get
			{
				return this._isOn;
			}
		}

		// Token: 0x060023F6 RID: 9206 RVA: 0x0047AF54 File Offset: 0x00479154
		public UIToggleImage(Texture2D texture, int width, int height, Point onTextureOffset, Point offTextureOffset)
		{
			this._onTexture = texture;
			this._offTexture = texture;
			this._offTextureOffset = offTextureOffset;
			this._onTextureOffset = onTextureOffset;
			this._drawWidth = width;
			this._drawHeight = height;
			this.Width.Set((float)width, 0f);
			this.Height.Set((float)height, 0f);
		}

		// Token: 0x060023F7 RID: 9207 RVA: 0x0047AFD0 File Offset: 0x004791D0
		protected override void DrawSelf(SpriteBatch spriteBatch)
		{
			CalculatedStyle dimensions = base.GetDimensions();
			Texture2D texture;
			Point point;
			if (this._isOn)
			{
				texture = this._onTexture;
				point = this._onTextureOffset;
			}
			else
			{
				texture = this._offTexture;
				point = this._offTextureOffset;
			}
			Color color = base.IsMouseHovering ? Color.White : Color.Silver;
			spriteBatch.Draw(texture, new Rectangle((int)dimensions.X, (int)dimensions.Y, this._drawWidth, this._drawHeight), new Rectangle?(new Rectangle(point.X, point.Y, this._drawWidth, this._drawHeight)), color);
		}

		// Token: 0x060023F8 RID: 9208 RVA: 0x0001974B File Offset: 0x0001794B
		public override void Click(UIMouseEvent evt)
		{
			this.Toggle();
			base.Click(evt);
		}

		// Token: 0x060023F9 RID: 9209 RVA: 0x0001975A File Offset: 0x0001795A
		public void SetState(bool value)
		{
			this._isOn = value;
		}

		// Token: 0x060023FA RID: 9210 RVA: 0x00019763 File Offset: 0x00017963
		public void Toggle()
		{
			this._isOn = !this._isOn;
		}

		// Token: 0x0400400C RID: 16396
		private Texture2D _onTexture;

		// Token: 0x0400400D RID: 16397
		private Texture2D _offTexture;

		// Token: 0x0400400E RID: 16398
		private int _drawWidth;

		// Token: 0x0400400F RID: 16399
		private int _drawHeight;

		// Token: 0x04004010 RID: 16400
		private Point _onTextureOffset = Point.Zero;

		// Token: 0x04004011 RID: 16401
		private Point _offTextureOffset = Point.Zero;

		// Token: 0x04004012 RID: 16402
		private bool _isOn;
	}
}
